package cn.leedsoft.and.crimeintent.model;

import android.content.Context;
import android.media.MediaPlayer;
import android.view.SurfaceHolder;
import cn.leedsoft.and.crimeintent.R;

/**
 * Created by leeds on 2016/8/9 22:05.
 */
public class VideoPlayer {
    private MediaPlayer mMediaPlayer;

    public void stop() {
        if (mMediaPlayer != null) {
            mMediaPlayer.release();
            mMediaPlayer = null;
        }
    }

    public void play(Context context, SurfaceHolder surfaceHolder) {
        stop();
//        Uri uri = Uri.parse("android.resource://cn.leedsoft.and.crimeintent.controller.hellomoon/raw/apollo_17_stroll");
//        mMediaPlayer = MediaPlayer.create(context, uri, surfaceHolder);
        mMediaPlayer = MediaPlayer.create(context, R.raw.apollo_17_stroll_1);
        mMediaPlayer.setDisplay(surfaceHolder);
        mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                stop();
            }
        });
        mMediaPlayer.start();
    }
}
